package com;

import Untils.JDBCUntils;

import java.sql.*;
import java.util.Scanner;

/*
需求：键盘输入账号与密码，判断是否正确
 */
public class Test6 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入账号");
        String user = sc.nextLine();
        System.out.println("请输入密码");
        String password = sc.nextLine();
        boolean flag = Test6.check(user, password);
          if(flag){
              System.out.println("验证成功");
          }else{
              System.out.println("验证失败");
          }
    }
    public static boolean check(String user,String password){
        if(user==null||password==null){
            return false;

        }
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
             conn = JDBCUntils.getconnection();
            String sql="select*from emp where user=? and password=?";
            ps = conn.prepareStatement(sql);
            ps.setString(1,user);
            ps.setString(2,password);
           rs = ps.executeQuery(sql);
                  return  rs.next();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            if(ps!=null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            JDBCUntils.close2(rs,null,conn);
        }
        return  false;
    }
}
